﻿using Service.Framework;
using Service.Framework.Utils;
using Service.Repository;
using SqlSugar;

namespace Service.Auth.Domain.AggregatesModel
{

    /// <summary>
    /// 菜单表
    /// </summary>
    [SugarTable("tb_permission")]
    public class Permission : Entity, IAggregateRoot
    {
        public Permission(string code, string name, bool isButton, bool isHide, string func, int orderSort, string icon,
            string description, string component)
        {
            Code = code;
            Name = name;
            IsButton = isButton;
            IsHide = isHide;
            Func = func;
            OrderSort = orderSort;
            Icon = icon;
            Description = description;
            Component = component;
        }

        public Permission()
        {
        }



        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "id", IsPrimaryKey = true)]
        public long Id { get; private set; }


        /// <summary>
        /// 菜单执行Action名
        /// </summary>
        [SugarColumn(ColumnName = "code")]
        public string Code { get; set; }


        /// <summary>
        /// 菜单显示名（如用户页、编辑(按钮)、删除(按钮)）
        /// </summary>
        [SugarColumn(ColumnName = "name")]
        public string Name { get; set; }

        /// <summary>
        /// 是否是按钮
        /// </summary>
        [SugarColumn(ColumnName = "is_button")]
        public bool IsButton { get; set; }




        /// <summary>
        /// 是否是隐藏菜单
        /// </summary>
        [SugarColumn(ColumnName = "is_hide")]
        public bool IsHide { get; set; }



        /// <summary>
        /// 按钮事件
        /// </summary>
        [SugarColumn(ColumnName = "func")]
        public string Func { get; set; }



        /// <summary>
        /// 排序
        /// </summary>
        [SugarColumn(ColumnName = "order_sort")]
        public int OrderSort { get; set; }



        /// <summary>
        /// 菜单图标
        /// </summary>
        [SugarColumn(ColumnName = "icon")]
        public string Icon { get; set; }



        /// <summary>
        /// 菜单描述    
        /// </summary>
        [SugarColumn(ColumnName = "description")]
        public string Description { get; set; }


        /// <summary>
        /// 父级id
        /// </summary>
        [SugarColumn(ColumnName = "parent_id")]
        public long ParentId { get; private set; }

        public void SetParenId(long value)
        {
            ParentId = value;
        }

        /// <summary>
        /// 如果是按钮一定要接口id
        /// </summary>
        [SugarColumn(ColumnName = "module_url", IsNullable = true)]
        public string ModuleUrl { get; private set; }


        public void SetModuleUrl(string value)
        {
            ModuleUrl = value;
        }


        /// <summary>
        /// 组件地址
        /// </summary>
        [SugarColumn(ColumnName = "component")]
        public string Component { get; set; }

        [SugarColumn(IsIgnore = true)]
        public List<string> Permissions { get; set; }



        [SugarColumn(IsIgnore = true)]
        public List<Permission> Children { get; set; }


    }
}
